|
|
|
|
|
|
|
This code will display a new Notepad child form every time you choose File, New from the menu. Next, add the following code to have the TextBox control cover the entire child form, no matter what size it is: |
|
|
|
|
|
|
|
|
Private Sub Form_Resize ()
TxtInput.Height = ScaleHeight
TxtInput.Width = ScaleWidth
End Sub |
|
|
|
|
|
|
|
|
Due to the way the child forms are displayed, any code that you place in the child form is shared by each instance of the form. When you have several copies of the form displayed, each unique form will recognize its own events. Because the same code is shared by each form, you might wonder how to reference the form that has actually called the code. |
|
|
|
|
|
|
|
|
When you're executing the application, you can choose to have the first child form displayed automatically by setting it as the Startup form. If you want an empty MDI form shown when you start the program, you need to change the Startup setting to the MDI parent name. |
|
|
|
|
|
|
|
|
Multiple Instances of the Child Form |
|
|
|
|
|
|
|
|
Although the MDI form can be used to make your application more organized, this misses the real power of an MDI application. The most powerful feature of an MDI application is in its ability to create and manipulate multiple instances of the child form at the same time. In fact, many true MDI applications are made up of only two forms: the MDI parent and the template form for all the children in the application. |
|
|
|
|
|
|
|
|
Note Your application isn't limited to only one type of child form template. For example, the Visual Basic interface uses two basic child form types: the Form design child form and the Code child form. And as you already know, you can have as many as you need open at the same time. |
|
|
|
|
|
|
|
|
|
After you have more than one child form created at a time, you need to use the MDI form's ActiveForm property, which returns the child form object with the focus or that's the most recently active. In the same light, when you're working with controls on the child form, you need to know exactly which control you're accessing. The ActiveControl property works the same way as the ActiveForm control by returning the control with the focus on the active child form. The following code shows an example of how to access text on the active child form: |
|
|
|
|
|
|
|
|
frmMDINote.ActiveForm.ActiveControl.Text = This is a Demo |
|
|
|
|
|